<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8">
    <script src="/async.js" class="script-hammerhead-shadow-ui"></script>
    <script src="/hammerhead.js" class="script-hammerhead-shadow-ui"></script>
    <script src="/core.js" class="script-hammerhead-shadow-ui"></script>
    <script src="/ui.js" class="script-hammerhead-shadow-ui"></script>
    <script src="/automation.js" class="script-hammerhead-shadow-ui"></script>
    <script src="/legacy-runner.js" class="script-hammerhead-shadow-ui"></script>
    <script src="/jquery.js" class="script-hammerhead-shadow-ui"></script>

    <link type="text/css" rel=stylesheet href="/ui.css" class="ui-stylesheet-hammerhead-shadow-ui">
</head>
<body>
<script type="text/javascript">
    function getTestCafeModule (module) {
        return window['%' + module + '%'];
    }


    //Hammerhead setup
    var hammerhead = getTestCafeModule('hammerhead');

    hammerhead.get('./utils/destination-location').forceLocation('http://localhost/sessionId/https://example.com');

    hammerhead.start({ sessionId: 'sessionId' });

    var testCafeLegacyRunner = getTestCafeModule('testCafeLegacyRunner');
    var sandboxedJQuery      = testCafeLegacyRunner.get('./sandboxed-jquery');
    var iframeDispatcher     = testCafeLegacyRunner.get('./iframe-dispatcher');

    sandboxedJQuery.init(window);

    var act          = null,
        ok           = null,
        notOk        = null,
        eq           = null,
        notEq        = null,
        runInContext = null;

    function onTestRunnerInitialized (testRunner, callback) {
        act   = testRunner.act;
        ok    = testRunner.ok;
        notOk = testRunner.notOk;
        eq    = testRunner.eq;
        notEq = testRunner.notEq;

        try {
            //!----------------------------------BEGIN HELPERS AND REQUIRES CODE----------------------------------
            "<@ sharedJs @>";
            //!------------------------------------END HELPERS AND REQUIRES CODE----------------------------------
        } catch (err) {
            act._onJSError(err);
            return;
        }

        runInContext = function (stepName, step, runner) {
            runner([stepName], [function () {
                eval('(' + step + ').call(this)');
            }]);
        };

        callback(runInContext);
    }

    iframeDispatcher.init(onTestRunnerInitialized);
</script>

<input id="button" type="button" value="simple button"/>
<input id="errorButton" type="button" value="error button"/>
<input id="xhrButton" type="button" value="xhr button"/>
<a id="link">Link</a>

<script>
    $(document).ready(function () {
        $('#link').click(function () {
            document.location = document.location.toString();
        });

        window.loadedTime = Date.now();

        $('#button').click(function () {
            window.top.postMessage(JSON.stringify({ type: "clickRaised" }), "*");
        });

        $('#errorButton').click(function () {
            throw 'error';
        });

        $('#xhrButton').click(function () {
            $.get('/xhr-test/1000', function () {
                window.xhrCompleted = true;
            });
        });
    });
</script>
</body>
</html>
